BiomeBase = class()

function BiomeBase:init(id,name)
    self.biomeId = id
    -- Biome的名字
    self.biomeName = name
    -- Biome顶部填充方块
    self.topBlock = Block.grass.id
    -- Biome普通填充方块
    self.fillBlock = Block.soil.id
    -- Biome能生成的最低高度(取值范围:0~1，表示从最低生成高度0到世界最高生成高度)
    self.minHeight = 0.4
    -- Biome能生成的最高高度(取值范围:0~1，表示从最低生成高度0到世界最高生成高度)
    self.maxHeight = 0.5
    -- Biome的温度(摄氏度)
    self.temperature = 20
    -- Biome的降雨量(就是降雨几率，取值范围:0~1，0代表永不降雨)
    self.rainfall = 0.1
    -- 此Biome中水的颜色
    self.waterColor = color(0, 136, 255, 255)
    -- 此Biome中草的颜色
    self.grassColor = color(105, 255, 0, 255)
    -- 此Biome是否能下雪
    self.enableSnow = false
    -- 此Biome是否能下雨
    self.enableRain = false
    
    self.biomeDecorator = {
        treesPerChunk = 0,
        grassPerChunk = 0,
        sandPerChunk = 0,
        flowersPerChunk = 0,
        deadBushPerChunk = 0
    }
    -- 是否开启3D地形生成
    self.enabled3DNoise = true
    -- 是否开启平滑光照亮度更新
    self.shouldUpdateBrightness = true
    
    Biome.biomeList[id] = self
end

function BiomeBase:decorate(world,rand,x,z)
    rand:begin()
    self:genOres(world,rand,x,z)
    self:genPlants(world,rand,x,z)
    rand:End()
end

-- 处理此Biome的3DNoise
function BiomeBase:processNoise3D(noiseValue,h)
    noiseValue = (noiseValue + (noiseValue - 0.5) * 0.1)
    noiseValue = noiseValue - h * 0.015
    return noiseValue
end

function BiomeBase:processNoise2D(baseNoise,terrainNoise)
    baseNoise = (0.5 + (baseNoise - 0.5) * 0.8) * 0.5
    terrainNoise = terrainNoise * 0.5
    terrainNoise = terrainNoise + baseNoise
    return self.minHeight + (terrainNoise * (self.maxHeight - self.minHeight))
end

function BiomeBase:genPlants(world,rand,x,z)
    local generator = PlantGen(world,rand)
    local y,id = world.height - 1,Block.grassBush.id
    local xa,za
    
    local count = self.biomeDecorator.grassPerChunk + rand:rndInt(-5,5)
    for i = 1,count do
        xa = x + rand:rndInt(0,15)
        za = z + rand:rndInt(0,15) 
        generator:generate(xa,y,za,id)
    end
    
    generator = TreeGen(world,rand)
    count = self.biomeDecorator.treesPerChunk + rand:rndInt(-3,3)
    for i = 1,count do
        xa = x + rand:rndInt(1,14)
        za = z + rand:rndInt(1,14) 
        generator:generate(xa,y,za)
    end
end

function BiomeBase:genOres(world,rand,x,z)
    
end
